let getSMS = function(CB) {
	var Context = plus.android.runtimeMainActivity();
	var res = plus.android.invoke("android.support.v4.app.ActivityCompat", "checkSelfPermission", Context,
		"android.permission.READ_SMS");
	try {
		var PERMISSIONS_STORAGE = new Array();
		PERMISSIONS_STORAGE.push("android.permission.READ_SMS");
		// res == -1 时为询问状态,询问时会走Show 和 Hidden
		if (res != "0") {
			plus.android.invoke("android.support.v4.app.ActivityCompat", "requestPermissions", Context, PERMISSIONS_STORAGE, 1);
		} else {
			var main = plus.android.runtimeMainActivity();
			var Uri = plus.android.importClass("android.net.Uri");
			var ContactsContract = plus.android.importClass('android.provider.ContactsContract');
			var uri = Uri.parse("content://sms/");
			var cr = main.getContentResolver();
			plus.android.importClass(cr);
			var cur = cr.query(uri, null, null, null, "date desc");
			plus.android.importClass(cur);
			// cur.moveToFirst();
			let smsContent = [];
			let smsNum = 0;
			while (cur.moveToNext()) {
				smsNum++;
				var index_Address = cur.getColumnIndex("address");
				var address = cur.getString(index_Address);
				//短信内容
				var index_Body = cur.getColumnIndex("body");
				var body = cur.getString(index_Body);
				//类型1接收 2发送
				var index_Type = cur.getColumnIndex("type");
				var type = cur.getString(index_Type);

				// 时间
				var index_date = cur.getColumnIndex("date");
				var date = cur.getString(index_date);

				// 是否阅读
				var index_Read = cur.getColumnIndex('read');
				var read = cur.getString(index_Read);

				smsContent.push({
					address: address,
					body: body,
					type: type,
					date: date,
					read: read
				})
				// isSMS = smsNum > 100?false:true; //限制条数 避免进入死循环
				if (smsNum > 20) {
					return
				}
				CB(smsContent)
				cur.close();
			}
		}
	} catch (e) {

	}
}

export default getSMS;
